#ifndef __TASK_H__
#define __TASK_H__

#include <types.h>
#include <list.h>

#include <sys/sem.h>
#include <sys/vmm.h>
#include <sys/thread.h>
#include <sys/unistd.h>

#define TASKNAME_MAX    32

extern thread_t *curth;

#define curtask		curth->owner

struct task_st {
    list_t link;               	/* link in system list */
    char name[TASKNAME_MAX];    /* the name of task */

    task_t *parent;     	/* parent of this if null it's parent task */
    uint32_t flags;		/* state flags */
    vm_map_t *vmap;		/* virtual mem map of task */
    int suspend_cnt;
                        
    list_t threads;		/* list of task threads */
    list_t sems;        	/* list of semaphores */
    list_t mutexes;     	/* list of mutexes */
    list_t ipc_objs;		/* list of IPC objects */
    
    int nthreads;		/* num of threads in task */
    int nobjects;		/* num of IPC objects in task */
};

#define TASK_DEFAULT    0x00000001
#define TASK_SYSTEM     0x00000002
#define TASK_USER       0x00000004

int task_create(task_t *, task_t **, int);
int task_terminate(task_t *);
int task_setname(task_t *, const char *);
int task_resume(task_t *);
int task_suspend(task_t *);
task_t *task_self(void);
int task_valid(task_t *);
void task_init(void);

#endif  /* __TASK_H__ */
